package com.gdth.bank.adapter;

import java.io.File;
import java.io.IOException;
import java.util.List;

import com.gdth.bank.R;
import com.gdth.bank.bean.CjkhItem;
import com.gdth.bank.bean.DzCpItem;
import com.gdth.bank.widget.image.Bimp;
import com.gdth.utils.FileUtil;
import com.gdth.utils.ImageUtil;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class DzCpKhPosListViewAdapter extends  BaseAdapter {
	protected Context context;  

 	protected List<DzCpItem> vList;
 
 	protected String filepath ;
 	protected int layout;
 	
 	public DzCpKhPosListViewAdapter(Context context, List<DzCpItem> vList) {  
        this.context = context;
        this.vList = vList;
        
        this.layout = R.layout.item_dzcp_pos;
    }
 	
 	public DzCpKhPosListViewAdapter(Context context, List<DzCpItem> vList,String filepath) {  
        this.context = context;
        this.vList = vList;
        this.filepath=filepath;
        this.layout = R.layout.item_dzcp_pos;
    }
 	public DzCpKhPosListViewAdapter(Context context, List<DzCpItem> vList, int layout) {  
        this.context = context;
        this.vList = vList;
        
        this.layout = layout;
    }
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return vList.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(final int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		DzCpItem model = vList.get(position);
		ViewHolder holder = null;
		if (convertView == null){
			holder = new ViewHolder();
			
			convertView = LayoutInflater.from(context).inflate(layout, null);
			
			holder.local_tp = (ImageView) convertView.findViewById(R.id.cjkh_item_tp);
//			holder.local_detail = (ImageView) convertView.findViewById(R.id.cjkh_item_detail);
		    holder.local_xm = (TextView) convertView.findViewById(R.id.cjkh_item_xm);
		    holder.local_sfz = (TextView) convertView.findViewById(R.id.cjkh_item_sfz);
		    holder.local_sj = (TextView) convertView.findViewById(R.id.cjkh_item_sj);
//		    holder.local_zt = (TextView) convertView.findViewById(R.id.cjkh_item_zt);
		    holder.local_lx = (TextView) convertView.findViewById(R.id.cjkh_item_lx);
//		    if (this.mOnCjjlDetailClickListener != null) {
//		    	holder.local_detail.setOnClickListener(new OnClickListener(){
//
//					@Override
//					public void onClick(View v) {
//						// TODO Auto-generated method stub
//						mOnCjjlDetailClickListener.clickListener(position);
//					}
//		    		
//		    	});
//		    }
//			
			convertView.setTag(holder);
        }
		
		else {
			holder = (ViewHolder) convertView.getTag();
		}
		
		if (holder != null){
			if (model.getImg() != null ){
				
		    	/*ImageUtil.downloadAsyncTask(holder.local_tp, model.getImg());*/
				
				/*File file = new File(model.getImg());
				if (file.exists()) {
					try {
						Bitmap bm =Bimp.getInstance().revitionImageSize(model.getImg());
						holder.local_tp.setImageBitmap(bm);
					} catch (IOException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
				}*/
                   
//            }
				/*Bitmap bitmap = FileUtil.getImageFromAssetsFile(context, model.getImg());*/
				if(model.getImg().toString().equals("ETC")){
				holder.local_tp.setImageDrawable(context.getResources().getDrawable(R.drawable.etc));
				}else if(model.getImg().toString().equals("POS")){
					holder.local_tp.setImageDrawable(context.getResources().getDrawable(R.drawable.pos));
				}
				
		    	
		    }/*else if(model.getImg() != null){
	    	ImageUtil.downloadAsyncTask(holder.local_tp, model.getImg());
		    }*/
			holder.local_xm.setText(model.getValue());
			holder.local_sfz.setText(model.getSfz());
			holder.local_sj.setText(model.getXsSj());
//			holder.local_zt.setText(model.getZt());
			holder.local_lx.setText(model.getLx());
			
		}
		
        return convertView;
	}
	public static class ViewHolder{
		public ImageView local_tp = null;
//		public ImageView local_detail = null;
		public TextView local_xm = null;
		public TextView local_sfz = null;
		public TextView local_sj = null;
//		public TextView local_zt = null;
		public TextView local_lx = null;
		
	}
private OnCjjlDetailClickListener mOnCjjlDetailClickListener;
	
	public void setOnCjjlDetailClickListener(OnCjjlDetailClickListener mOnCjjlDetailClickListener) {
		this.mOnCjjlDetailClickListener = mOnCjjlDetailClickListener;
	}
	
	public interface OnCjjlDetailClickListener {
		void clickListener(int position);
	}
}
